﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibHuman;

namespace Human
{
	/// <summary>
	/// Summary description for frmNghiviec.
	/// </summary>
	public class frmNghiphep : System.Windows.Forms.Form
	{
        private AccessData mDB = new AccessData();
        Language lan = new Language();
		private DataSet ds=new DataSet();
        private DataSet ds1 = new DataSet();
		private System.Windows.Forms.DataGrid dgrDanhMuc7;
		private System.Windows.Forms.TextBox txtTen;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox txtMa;
		private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Panel panel1;
        private Button butKetthuc;
        private Button butHuy;
        private Button butBoqua;
        private Button butLuu;
        private Button butSua;
        private Button butThem;
        private Panel panel2;
        private ComboBox cbo_nhombc;
        private Label label3;
        private TextBox txt_stt;
        private Label label4;
        private TextBox txt_kihieu;
        private Label label5;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmNghiphep()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
            lan.Read_Language_to_Xml(this.Name.ToString(), this);
            lan.Changelanguage_to_English(this.Name.ToString(), this);
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmNghiphep));
            this.dgrDanhMuc7 = new System.Windows.Forms.DataGrid();
            this.txtTen = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.txtMa = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.panel1 = new System.Windows.Forms.Panel();
            this.butKetthuc = new System.Windows.Forms.Button();
            this.butHuy = new System.Windows.Forms.Button();
            this.butBoqua = new System.Windows.Forms.Button();
            this.butLuu = new System.Windows.Forms.Button();
            this.butSua = new System.Windows.Forms.Button();
            this.butThem = new System.Windows.Forms.Button();
            this.panel2 = new System.Windows.Forms.Panel();
            this.txt_kihieu = new System.Windows.Forms.TextBox();
            this.label5 = new System.Windows.Forms.Label();
            this.txt_stt = new System.Windows.Forms.TextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.cbo_nhombc = new System.Windows.Forms.ComboBox();
            this.label3 = new System.Windows.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)(this.dgrDanhMuc7)).BeginInit();
            this.panel1.SuspendLayout();
            this.panel2.SuspendLayout();
            this.SuspendLayout();
            // 
            // dgrDanhMuc7
            // 
            this.dgrDanhMuc7.AlternatingBackColor = System.Drawing.Color.Lavender;
            this.dgrDanhMuc7.BackColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDanhMuc7.BackgroundColor = System.Drawing.SystemColors.Control;
            this.dgrDanhMuc7.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.dgrDanhMuc7.CaptionBackColor = System.Drawing.Color.LightSteelBlue;
            this.dgrDanhMuc7.CaptionForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc7.CaptionVisible = false;
            this.dgrDanhMuc7.DataMember = "";
            this.dgrDanhMuc7.FlatMode = true;
            this.dgrDanhMuc7.Font = new System.Drawing.Font("Tahoma", 8F);
            this.dgrDanhMuc7.ForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc7.GridLineColor = System.Drawing.Color.Gainsboro;
            this.dgrDanhMuc7.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
            this.dgrDanhMuc7.HeaderBackColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc7.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
            this.dgrDanhMuc7.HeaderForeColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDanhMuc7.LinkColor = System.Drawing.Color.Teal;
            this.dgrDanhMuc7.Location = new System.Drawing.Point(3, 3);
            this.dgrDanhMuc7.Name = "dgrDanhMuc7";
            this.dgrDanhMuc7.ParentRowsBackColor = System.Drawing.Color.Gainsboro;
            this.dgrDanhMuc7.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc7.RowHeaderWidth = 10;
            this.dgrDanhMuc7.SelectionBackColor = System.Drawing.Color.CadetBlue;
            this.dgrDanhMuc7.SelectionForeColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDanhMuc7.Size = new System.Drawing.Size(638, 404);
            this.dgrDanhMuc7.TabIndex = 1;
            this.dgrDanhMuc7.CurrentCellChanged += new System.EventHandler(this.dgrDanhMuc7_CurrentCellChanged);
            // 
            // txtTen
            // 
            this.txtTen.BackColor = System.Drawing.Color.White;
            this.txtTen.ForeColor = System.Drawing.Color.DarkBlue;
            this.txtTen.Location = new System.Drawing.Point(137, 8);
            this.txtTen.MaxLength = 50;
            this.txtTen.Name = "txtTen";
            this.txtTen.Size = new System.Drawing.Size(121, 20);
            this.txtTen.TabIndex = 1;
            this.txtTen.Validated += new System.EventHandler(this.txtTen_Validated);
            this.txtTen.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtTen_KeyDown);
            // 
            // label2
            // 
            this.label2.BackColor = System.Drawing.SystemColors.Control;
            this.label2.ForeColor = System.Drawing.Color.DarkBlue;
            this.label2.Location = new System.Drawing.Point(99, 11);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(39, 13);
            this.label2.TabIndex = 5;
            this.label2.Text = "Lý do :";
            this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // txtMa
            // 
            this.txtMa.BackColor = System.Drawing.Color.White;
            this.txtMa.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtMa.Enabled = false;
            this.txtMa.ForeColor = System.Drawing.Color.DarkBlue;
            this.txtMa.Location = new System.Drawing.Point(54, 8);
            this.txtMa.MaxLength = 2;
            this.txtMa.Name = "txtMa";
            this.txtMa.Size = new System.Drawing.Size(41, 20);
            this.txtMa.TabIndex = 0;
            this.txtMa.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtMa_KeyDown);
            // 
            // label1
            // 
            this.label1.BackColor = System.Drawing.SystemColors.Control;
            this.label1.ForeColor = System.Drawing.Color.DarkBlue;
            this.label1.Location = new System.Drawing.Point(3, 12);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(53, 13);
            this.label1.TabIndex = 4;
            this.label1.Text = "Mã lý do :";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // panel1
            // 
            this.panel1.Controls.Add(this.butKetthuc);
            this.panel1.Controls.Add(this.butHuy);
            this.panel1.Controls.Add(this.butBoqua);
            this.panel1.Controls.Add(this.butLuu);
            this.panel1.Controls.Add(this.butSua);
            this.panel1.Controls.Add(this.butThem);
            this.panel1.Location = new System.Drawing.Point(68, 28);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(457, 39);
            this.panel1.TabIndex = 7;
            // 
            // butKetthuc
            // 
            this.butKetthuc.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butKetthuc.ForeColor = System.Drawing.Color.DarkBlue;
            this.butKetthuc.Image = global::Human.Properties.Resources.close_r1;
            this.butKetthuc.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butKetthuc.Location = new System.Drawing.Point(380, 5);
            this.butKetthuc.Name = "butKetthuc";
            this.butKetthuc.Size = new System.Drawing.Size(65, 28);
            this.butKetthuc.TabIndex = 5;
            this.butKetthuc.Text = "&Thoát";
            this.butKetthuc.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butKetthuc.UseVisualStyleBackColor = true;
            this.butKetthuc.Click += new System.EventHandler(this.butKetthuc_Click);
            // 
            // butHuy
            // 
            this.butHuy.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butHuy.ForeColor = System.Drawing.Color.DarkBlue;
            this.butHuy.Image = global::Human.Properties.Resources.delete_enabled;
            this.butHuy.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butHuy.Location = new System.Drawing.Point(309, 5);
            this.butHuy.Name = "butHuy";
            this.butHuy.Size = new System.Drawing.Size(65, 28);
            this.butHuy.TabIndex = 4;
            this.butHuy.Text = "&Hủy";
            this.butHuy.UseVisualStyleBackColor = true;
            this.butHuy.Click += new System.EventHandler(this.butHuy_Click);
            // 
            // butBoqua
            // 
            this.butBoqua.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butBoqua.ForeColor = System.Drawing.Color.DarkBlue;
            this.butBoqua.Image = ((System.Drawing.Image)(resources.GetObject("butBoqua.Image")));
            this.butBoqua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butBoqua.Location = new System.Drawing.Point(233, 5);
            this.butBoqua.Name = "butBoqua";
            this.butBoqua.Size = new System.Drawing.Size(70, 28);
            this.butBoqua.TabIndex = 3;
            this.butBoqua.Text = "   &Bỏ qua";
            this.butBoqua.UseVisualStyleBackColor = true;
            this.butBoqua.Click += new System.EventHandler(this.butBoqua_Click);
            // 
            // butLuu
            // 
            this.butLuu.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butLuu.ForeColor = System.Drawing.Color.DarkBlue;
            this.butLuu.Image = ((System.Drawing.Image)(resources.GetObject("butLuu.Image")));
            this.butLuu.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butLuu.Location = new System.Drawing.Point(163, 5);
            this.butLuu.Name = "butLuu";
            this.butLuu.Size = new System.Drawing.Size(65, 28);
            this.butLuu.TabIndex = 2;
            this.butLuu.Text = "&Lưu";
            this.butLuu.UseVisualStyleBackColor = true;
            this.butLuu.Click += new System.EventHandler(this.butLuu_Click);
            // 
            // butSua
            // 
            this.butSua.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butSua.ForeColor = System.Drawing.Color.DarkBlue;
            this.butSua.Image = global::Human.Properties.Resources.quick_edit;
            this.butSua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butSua.Location = new System.Drawing.Point(92, 5);
            this.butSua.Name = "butSua";
            this.butSua.Size = new System.Drawing.Size(65, 28);
            this.butSua.TabIndex = 1;
            this.butSua.Text = "&Sửa";
            this.butSua.UseVisualStyleBackColor = true;
            this.butSua.Click += new System.EventHandler(this.butSua_Click);
            // 
            // butThem
            // 
            this.butThem.Enabled = false;
            this.butThem.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butThem.ForeColor = System.Drawing.Color.DarkBlue;
            this.butThem.Image = global::Human.Properties.Resources.add;
            this.butThem.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butThem.Location = new System.Drawing.Point(21, 5);
            this.butThem.Name = "butThem";
            this.butThem.Size = new System.Drawing.Size(65, 28);
            this.butThem.TabIndex = 0;
            this.butThem.Text = "    &Thêm";
            this.butThem.UseVisualStyleBackColor = true;
            this.butThem.Visible = false;
            this.butThem.Click += new System.EventHandler(this.butThem_Click);
            // 
            // panel2
            // 
            this.panel2.BackColor = System.Drawing.SystemColors.Control;
            this.panel2.Controls.Add(this.txt_kihieu);
            this.panel2.Controls.Add(this.label5);
            this.panel2.Controls.Add(this.txt_stt);
            this.panel2.Controls.Add(this.label4);
            this.panel2.Controls.Add(this.cbo_nhombc);
            this.panel2.Controls.Add(this.txtTen);
            this.panel2.Controls.Add(this.panel1);
            this.panel2.Controls.Add(this.txtMa);
            this.panel2.Controls.Add(this.label3);
            this.panel2.Controls.Add(this.label2);
            this.panel2.Controls.Add(this.label1);
            this.panel2.Location = new System.Drawing.Point(3, 406);
            this.panel2.Name = "panel2";
            this.panel2.Size = new System.Drawing.Size(638, 69);
            this.panel2.TabIndex = 0;
            // 
            // txt_kihieu
            // 
            this.txt_kihieu.BackColor = System.Drawing.Color.White;
            this.txt_kihieu.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txt_kihieu.ForeColor = System.Drawing.Color.DarkBlue;
            this.txt_kihieu.Location = new System.Drawing.Point(317, 9);
            this.txt_kihieu.MaxLength = 3;
            this.txt_kihieu.Name = "txt_kihieu";
            this.txt_kihieu.Size = new System.Drawing.Size(56, 20);
            this.txt_kihieu.TabIndex = 2;
            this.txt_kihieu.Validated += new System.EventHandler(this.txt_kihieu_Validated);
            this.txt_kihieu.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txt_kihieu_KeyDown);
            // 
            // label5
            // 
            this.label5.BackColor = System.Drawing.SystemColors.Control;
            this.label5.ForeColor = System.Drawing.Color.DarkBlue;
            this.label5.Location = new System.Drawing.Point(264, 12);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(47, 13);
            this.label5.TabIndex = 7;
            this.label5.Text = "Kí hiệu :";
            this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // txt_stt
            // 
            this.txt_stt.Location = new System.Drawing.Point(580, 8);
            this.txt_stt.Name = "txt_stt";
            this.txt_stt.Size = new System.Drawing.Size(45, 20);
            this.txt_stt.TabIndex = 4;
            this.txt_stt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txt_stt_KeyDown);
            // 
            // label4
            // 
            this.label4.BackColor = System.Drawing.SystemColors.Control;
            this.label4.ForeColor = System.Drawing.Color.DarkBlue;
            this.label4.Location = new System.Drawing.Point(540, 10);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(40, 13);
            this.label4.TabIndex = 6;
            this.label4.Text = "Số TT:";
            this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // cbo_nhombc
            // 
            this.cbo_nhombc.FormattingEnabled = true;
            this.cbo_nhombc.Items.AddRange(new object[] {
            "Nghỉ có lương\t",
            "Nghỉ không lương",
            "Nghỉ BH trả thay",
            "Nghỉ khác",
            "Chấm công thường trực"});
            this.cbo_nhombc.Location = new System.Drawing.Point(426, 7);
            this.cbo_nhombc.Name = "cbo_nhombc";
            this.cbo_nhombc.Size = new System.Drawing.Size(108, 21);
            this.cbo_nhombc.TabIndex = 3;
            this.cbo_nhombc.KeyDown += new System.Windows.Forms.KeyEventHandler(this.cbo_nhombc_KeyDown);
            // 
            // label3
            // 
            this.label3.BackColor = System.Drawing.SystemColors.Control;
            this.label3.ForeColor = System.Drawing.Color.DarkBlue;
            this.label3.Location = new System.Drawing.Point(379, 11);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(41, 13);
            this.label3.TabIndex = 5;
            this.label3.Text = "Nhóm :";
            this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // frmNghiphep
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(644, 475);
            this.Controls.Add(this.panel2);
            this.Controls.Add(this.dgrDanhMuc7);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "frmNghiphep";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = " Lý do nghỉ phép";
            this.Load += new System.EventHandler(this.frmNghiviec_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dgrDanhMuc7)).EndInit();
            this.panel1.ResumeLayout(false);
            this.panel2.ResumeLayout(false);
            this.panel2.PerformLayout();
            this.ResumeLayout(false);

		}
		#endregion

		private void frmNghiviec_Load(object sender, System.EventArgs e)
		{
			LoadGridTableStyle();
			enable_control(true);
            enable_textbox(false);
			refresh_Text();			
			butSua.Focus();
		}

		private void LoadGridTableStyle()
		{
            //DataSet ds1=new DataSet();
            string sql = " select ma as heso,ten as diengiai,stt,kihieu_phep as kihieu,";
            sql += " case substring(nhombc,1,2)";
            sql += " when 'CL' then 'Nghỉ có lương'";
            sql += " when 'KL' then 'Nghỉ không lương'";
            sql += " when 'BH' then 'Nghỉ bảo hiểm trả thay'";
            sql += " when 'KH' then 'Nghỉ khác'";
            sql += " when 'TR' then 'Chấm công thường trực' end as nhombc";
            sql += " from " + mDB.user + ".dmlydo_phep order by stt";
			ds1=mDB.get_data(sql);

			dgrDanhMuc7.DataSource=null;
			dgrDanhMuc7.TableStyles.Clear();
			DataGridTableStyle ts = new DataGridTableStyle();
			ts.MappingName = ds1.Tables[0].TableName;
			ts.AlternatingBackColor = Color.Beige;
			ts.BackColor = Color.GhostWhite;
			ts.ForeColor = Color.MidnightBlue;
			ts.GridLineColor = Color.RoyalBlue;
			ts.HeaderBackColor = Color.MidnightBlue;
			ts.HeaderForeColor = Color.Lavender;
			ts.SelectionBackColor = Color.Teal;
			ts.SelectionForeColor = Color.PaleGreen;
			
			DataGridTextBoxColumn TextCol1=new DataGridTextBoxColumn();
			TextCol1.MappingName = "heso";
			TextCol1.HeaderText = lan.Change_language_MessageText("Mã lý do");
			TextCol1.Width = 80;
			TextCol1.ReadOnly=true;
			TextCol1.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol1);
			dgrDanhMuc7.TableStyles.Add(ts);

            TextCol1 = new DataGridTextBoxColumn();
            TextCol1.MappingName = "diengiai";
            TextCol1.HeaderText = lan.Change_language_MessageText("Lý do");
            TextCol1.Width = 200;
            TextCol1.ReadOnly = true;
            TextCol1.Alignment = HorizontalAlignment.Left;
            ts.GridColumnStyles.Add(TextCol1);
			dgrDanhMuc7.TableStyles.Add(ts);

            TextCol1 = new DataGridTextBoxColumn();
            TextCol1.MappingName = "ldthoiviec";
            TextCol1.HeaderText = lan.Change_language_MessageText("Thôi việc");
            TextCol1.Width = 80;
            TextCol1.ReadOnly = true;
            TextCol1.Alignment = HorizontalAlignment.Left;
            ts.GridColumnStyles.Add(TextCol1);
            dgrDanhMuc7.TableStyles.Add(ts);

            TextCol1 = new DataGridTextBoxColumn();
            TextCol1.MappingName = "stt";
            TextCol1.HeaderText = lan.Change_language_MessageText("STT");
            TextCol1.Width = 80;
            TextCol1.ReadOnly = true;
            TextCol1.Alignment = HorizontalAlignment.Left;
            ts.GridColumnStyles.Add(TextCol1);
            dgrDanhMuc7.TableStyles.Add(ts);

            TextCol1 = new DataGridTextBoxColumn();
            TextCol1.MappingName = "kihieu";
            TextCol1.HeaderText = lan.Change_language_MessageText("Kí hiệu phép");
            TextCol1.Width = 80;
            TextCol1.ReadOnly = true;
            TextCol1.Alignment = HorizontalAlignment.Left;
            ts.GridColumnStyles.Add(TextCol1);
            dgrDanhMuc7.TableStyles.Add(ts);

            TextCol1 = new DataGridTextBoxColumn();
            TextCol1.MappingName = "nhombc";
            TextCol1.HeaderText = lan.Change_language_MessageText("Nhóm báo cáo");
            TextCol1.Width = 200;
            TextCol1.ReadOnly = true;
            TextCol1.Alignment = HorizontalAlignment.Left;
            ts.GridColumnStyles.Add(TextCol1);
            dgrDanhMuc7.TableStyles.Add(ts);

            ts.DataGrid.DataSource=ds1.Tables[0];
            CurrencyManager cm = (CurrencyManager)BindingContext[dgrDanhMuc7.DataSource, dgrDanhMuc7.DataMember];
            DataView dv = (DataView)cm.List;
            dv.AllowNew = false;
            dv.AllowEdit = false;
            dv.AllowDelete = false;
		}

		private void butThem_Click(object sender, System.EventArgs e)
		{
            clear_Text();
			enable_control(false);
			enable_textbox(true);
		}

		private void enable_control(bool ena)
		{
			butSua.Enabled=!ena;
			butLuu.Enabled=!ena;
			butBoqua.Enabled=!ena;
			butHuy.Enabled=!ena;
			butKetthuc.Enabled=ena;
		}
		
        private void enable_textbox(bool ena)
		{
            txtTen.Enabled = ena;
            cbo_nhombc.Enabled = ena;
            txt_stt.Enabled = ena;
            txt_kihieu.Enabled = ena;
		}
		
        private void clear_Text()
		{			
			txtTen.Clear();
            txtMa.Clear();
            txt_stt.Clear();
            txt_kihieu.Clear();
		}

		private void refresh_Text()
		{
            CurrencyManager cm = (CurrencyManager)BindingContext[dgrDanhMuc7.DataSource, dgrDanhMuc7.DataMember];
            DataView dv = (DataView)cm.List;
            dv.AllowNew = false;
            dv.AllowEdit = false;
            dv.AllowDelete = false;
            string nhombc;
            int i = dgrDanhMuc7.CurrentRowIndex;
			if(i>=0 && i<dv.Table.Rows.Count)
			{
                txtMa.Text = dv[i]["heso"].ToString();
                txtTen.Text = dv[i]["diengiai"].ToString();
                txt_stt.Text = dv[i]["stt"].ToString();
                txt_kihieu.Text = dv[i]["kihieu"].ToString();
                nhombc = dv[i]["nhombc"].ToString().Trim();
                if (nhombc == "Nghỉ có lương")
                    cbo_nhombc.SelectedIndex = 0;
                else
                    if (nhombc == "Nghỉ không lương")
                        cbo_nhombc.SelectedIndex = 1;
                    else
                        if (nhombc == "Nghỉ BH trả thay")
                            cbo_nhombc.SelectedIndex = 2;
                        else
                            if (nhombc == "Nghỉ khác")
                                cbo_nhombc.SelectedIndex = 3;
                            else
                                if (nhombc == "Chấm công thường trực")
                                    cbo_nhombc.SelectedIndex = 4;
			}
		}

		private void butSua_Click(object sender, System.EventArgs e)
		{
			enable_control(false);
            enable_textbox(true);
            butSua.Enabled = false;
			txtTen.Focus();
		}

        private bool kiemtra()
        {
            if (txtMa.Text.Trim() == ""||txtMa.Text.Trim().Length!=2)
            {
                MessageBox.Show(lan.Change_language_MessageText("Nhập mã lý do nghỉ việc!"), AccessData.Msg, MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtMa.Focus();
                return false;
            }
            if (txtTen.Text.Trim() == "")
            {
                MessageBox.Show(lan.Change_language_MessageText("Nhập tên lý do nghỉ việc!"), AccessData.Msg, MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtTen.Focus();
                return false;
            }
            return true;
        }

		private void butLuu_Click(object sender, System.EventArgs e)
		{
			try
			{
                string n_ma = "", n_ten = "",nhombc="",kihieu="";
                decimal stt = 0;
                if (txtMa.Text == "")
                {
                    MessageBox.Show(lan.Change_language_MessageText("Nhập mã!"), AccessData.Msg, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtMa.Focus();
                    return;
                }
                //
                if (txtTen.Text == "")
                {
                    MessageBox.Show(lan.Change_language_MessageText("Nhập lý do phép!"), AccessData.Msg, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtTen.Focus();
                    return;
                }
                n_ma = txtMa.Text.Trim();
                n_ten = txtTen.Text.Trim();
                kihieu = txt_kihieu.Text.Trim();
                if (txt_stt.Text != "")
                {
                    stt = decimal.Parse(txt_stt.Text);
                }
                else
                {
                    stt = 0;
                }
                if (cbo_nhombc.SelectedIndex == 0)
                {
                    nhombc = "CL";
                }
                else
                    if (cbo_nhombc.SelectedIndex == 1)
                    {
                        nhombc = "KL";
                    }
                    else
                        if (cbo_nhombc.SelectedIndex == 2)
                        {
                            nhombc = "BH";
                        }
                        else
                            if (cbo_nhombc.SelectedIndex == 3)
                            {
                                nhombc = "KH";
                            }
                            else
                                if (cbo_nhombc.SelectedIndex == 4)
                                {
                                    nhombc = "TR";
                                }                    
                
                if (!mDB.upd_nghiphep(n_ma, n_ten,nhombc,stt,kihieu))
                {
                    MessageBox.Show(lan.Change_language_MessageText("Không cập nhật thông tin nghỉ phép!"), AccessData.Msg, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    butBoqua.Focus();
                    return;
                }
				LoadGridTableStyle();	
				enable_control(true);				
				enable_textbox(false);
				butSua.Focus();
			}    
			catch{}
		}

		private void butBoqua_Click(object sender, System.EventArgs e)
		{
			enable_control(true);
            enable_textbox(false);
			butSua.Focus();
		}

		private void butHuy_Click(object sender, System.EventArgs e)
		{
			DialogResult dr = MessageBox.Show(lan.Change_language_MessageText("Đồng ý huỷ thông tin này?"),AccessData.Msg,MessageBoxButtons.YesNo);			
			if(dr == DialogResult.Yes) 			
			{
				mDB.get_data("delete from "+mDB.user+".dmlydo_phep where ma='"+txtMa.Text.Trim()+"'");
			}
			LoadGridTableStyle();
			refresh_Text();
            enable_textbox(false);
            enable_control(true);
		}

		private void butKetthuc_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void dgrDanhMuc7_CurrentCellChanged(object sender, System.EventArgs e)
		{
			refresh_Text();
			enable_textbox(false);
			enable_control(false);
            butSua.Focus();
            butLuu.Enabled = false;
		}

		private void txtTen_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab}");
		}

        private void txtMa_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter) SendKeys.Send("{Tab}");
        }

        private void cbo_nhombc_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                txt_stt.Focus();
        }

        private void txt_stt_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                butLuu.Focus();
        }

        private void txt_kihieu_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab}{F4}");
        }

        private void txtTen_Validated(object sender, EventArgs e)
        {
            
                txt_kihieu.Text =txtMa.Text;
            
        }

        private void txt_kihieu_Validated(object sender, EventArgs e)
        {
            string kihieu = "";
            kihieu = txt_kihieu.Text;
            if (txt_kihieu.Text != null)
            {

                foreach (DataRow dr in ds1.Tables[0].Rows)
                {
                    if (kihieu == dr["kihieu"].ToString())
                    {

                        MessageBox.Show(lan.Change_language_MessageText("Kí hiệu này đã có"),AccessData.Msg, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        
                        return;
                    }
                }
            }           
        }
	}
}
